package com.chuanjiabao.wisdom.guide;

import android.databinding.DataBindingUtil;
import android.support.annotation.DrawableRes;
import android.view.LayoutInflater;
import android.view.View;

import com.blog.www.guideview.Component;
import com.blog.www.guideview.Guide;
import com.chuanjiabao.wisdom.R;
import com.chuanjiabao.wisdom.databinding.LayerUploadBinding;
import com.chuanjiabao.wisdom.listener.OnBHClickListener;

public class EndComponent implements Component {

    private OnBHClickListener onBHClickListener;
    private Guide mGuide;
    private String title, hint;
    private int resId = -1;

    @Override
    public View getView(LayoutInflater inflater) {
        LayerUploadBinding binding = DataBindingUtil.inflate(
                inflater,
                R.layout.layer_upload,
                null,
                false
        );

        if (title != null) binding.tvModuleTitle.setText(title);
        if (hint != null) binding.tvModuleHint.setText(hint);
        if (resId > -1) binding.ivModuleImg.setImageResource(resId);

        binding.tvModuleIgnore.setOnClickListener(v -> {
            if (mGuide != null) mGuide.dismiss();

            if (onBHClickListener != null) {
                onBHClickListener.onCloseClick();
            }
        });

        binding.tvModuleNext.setOnClickListener(v -> {
            if (mGuide != null) mGuide.dismiss();

            if (onBHClickListener != null) {
                onBHClickListener.onConfirmClick();
            }
        });

        return binding.getRoot();
    }

    @Override
    public int getAnchor() {
        return Component.ANCHOR_BOTTOM;
    }

    @Override
    public int getFitPosition() {
        return Component.FIT_END;
    }

    @Override
    public int getXOffset() {
        return 0;
    }

    @Override
    public int getYOffset() {
        return 15;
    }

    @Override
    public void attact(Guide guide) {
        this.mGuide = guide;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setHint(String hint) {
        this.hint = hint;
    }

    public void setImage(@DrawableRes int resId) {
        this.resId = resId;
    }

    public void setOnBHClickListener(OnBHClickListener onBHClickListener) {
        this.onBHClickListener = onBHClickListener;
    }

}
